import Vue from 'vue'
import Vuex from 'vuex'
let timer = null

Vue.use(Vuex)
const store = new Vuex.Store({
	state: {
		phoneNum: '',
		openId: '',
		uploadImg: [],
		unReadNum: 0,
		showAppLoading: true,
		commitswitchTag: 0,
		flag: false,
		deviceType: '',
		userInfo: uni.getStorageSync('userInfo') ? JSON.parse(uni.getStorageSync('userInfo')) : {},
		showMask: '',
		maskPageParams: {},
		showPcTipsListCount: 0,
		lang: uni.getStorageSync('lang') || 'zh-Hans',
		zd: {},
		showArea: true,
		memberList: [],
		phone: '',
		refreshState: '',
		showMenu: false
	},
	mutations: {
		setUploadImg(state, v) {
			state.uploadImg = v
		},
		setPhoneNum(state, v) {
			state.phoneNum = v
		},
		setOpenId(state, v) {
			state.openId = v
		},
		setunReadNum(state, v) {
			state.unReadNum = v
		},
		setshowAppLoading(state, v) {
			state.showAppLoading = v
		},
		setcommitswitchTag(state, v) {
			state.commitswitchTag = v
		},
		setflag(state) {
			state.flag = true
			timer = setTimeout(() => {
				state.flag = false
			}, 1000)
		},
		setdeviceType(state, v) {
			state.deviceType = v
		},
		setuserInfo(state, v) {
			uni.setStorageSync('userInfo', JSON.stringify(v))
			state.userInfo = v
		},
		setshowMask(state, v) {
			state.showMask = v
			if (!v) {
				state.maskPageParams = {}
			}
		},
		setmaskPageParams(state, v) {
			state.maskPageParams = v
		},
		setShowPcTipsListCount(state, v) {
			state.showPcTipsListCount++
		},
		setLang(state, v) {
			state.lang = v
		},
		setzd(state, v) {
			state.zd = v
		},
		setshowArea(state, v) {
			state.showArea = v
		},
		setmemberList(state, v) {
			state.memberList = v
		},
		setphone(state, v) {
			state.phone = v
		},
		setRefreshState(state, v) {
			state.refreshState = v
		},
		setShowMenu(state, v) {
			state.showMenu = v
		}
	},
	actions: {}
})
export default store